<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	
	/**
	 * 
	 * Initial view layout
	 */
	protected function _initView() {
		//initialize View
		$view = new Zend_View ();
		$view->doctype ( 'XHTML1_TRANSITIONAL' );
		$view->headTitle ( '' );
		$view->setEncoding('UTF-8');
		$view->skin = "default";
		
		//add view to viewRenderer
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper ( "ViewRenderer" );
		$viewRenderer->setView ( $view );
		return $view;
	
	}
	/**
	 * 
	 * Initail class  for application
	 */
	protected function _initAutoLoad(){
		//load model class and entites in application
		$applicationLoader = new Zend_Loader_Autoloader_Resource(
			array(
				"namespace"		=>	"",
				"basePath"		=>	APPLICATION_PATH,
				"resourceTypes" => array(
					"model" => array(
						"path" => "/models/", "namespace"=>"Model"
					),
					"entity" => array(
						"path" => "/models/entities/", "namespace" => "Entity"
					),
					"form" => array(
						"path" => "/forms/", "namespace" => "Form"
					)
				)
			
			)
		);

		//load all class in library
		$libraryLoader = new Zend_Loader_Autoloader_Resource(
			array(
				"namespace"		=>	"",
				"basePath"		=>	LIBRARY_PATH,
				"resourceTypes" => array(
					"Auth_Adapter" => array(
						"path" => "/Auth/Adapter/", "namespace"=>"Auth_Adapter"
					),
					"Constain" => array(
						"path" => "/Constain/", "namespace"=>"Constain"
					),
					"Helper" => array(
						"path" => "/Helper/", "namespace"=>"Helper"
					),
					"Plugin" => array(
						"path" => "/Plugin/", "namespace"=>"Plugin"
					)
				)
			
			)
		);
		
		//$resourceLoader->addResourceType("model", "models", "Model_");
	}
	
	
	/**
	 * 
	 * Initial Layout
	 */
	protected function _initLayout(){
		$layoutLoader = new Plugin_ChangeLayout();
		$frontController = Zend_Controller_Front::getInstance();
		$frontController->registerPlugin($layoutLoader);
	}
	
	/**
	 * 
	 * Initial Routes
	 * Add custom routes for website
	 */
	protected function _initRoutes(){
		$controller = Zend_Controller_Front::getInstance();
		$router = $controller->getRouter();
		$defaultRoute = new Zend_Controller_Router_Route_Static(
       							"",
       							array(
       								"module" => "front",
       								"controller" => "index",
       								"action"	=>	"index"
       							)
       	);
       	$router->addRoute("default", $defaultRoute);
		
		
       	
       	//product route
       	//url ~/may-in-canon-lc200.html
        $router->addRoute(
        			"product",
        			new Zend_Controller_Router_Route_Regex(
								'([a-z0-9-]*).html',					// route pattern
                                array(
                                	'module'		=> 'front',			//module name
                                	'controller' 	=> 'product',			//controller name
                                    'action' 		=> 'index'
                              	),
                              	array(
                              		1 => "slug"
                              	),
                              	"%s.html"
                            )
       	);
       	//url ~/ket-qua-tim-kiem
        $router->addRoute(
        	'search',
        		new Zend_Controller_Router_Route_Static(
        		'ket-qua-tim-kiem.html',
        		array(
        			'module' => 'front',
        			'controller' => 'pcategory',
        			'action' => 'search'
        		)
        	)
        );
       	
        //url ~/doi-net-ve-cuong-phu/
        $router->addRoute(
        			'post',
        			new Zend_Controller_Router_Route_Regex(
        					'([a-z0-9-]+).htm',
        					array(
        						'module' => 'front',
        						'controller' => 'post',
        						'action'	=> 'index'
        					),
        					array(
        						1 => 'slug'
        					),
        					'%s.htm'
        			)			
        );
        //url ~/may-in-laser.html/
        $router->addRoute(
        		'pcategory',
        			new Zend_Controller_Router_Route_Regex(
        					'([a-z0-9-]*)_c([0-9]*)((_p[0-9]+)?).html',
        					array(
        						'module' => 'front',
        						'controller' => 'pcategory',
        						'action'	=> 'index',
        						'page' => 1
        					),
        					array(
        						1 => 'cat_name',
        						2 => 'cat_id',
        						3 => 'page'
        					),
        					'%s_c%s%s.html'
        			)
        );
        
        //url ~/chuyen-muc-nguoi-dung
        $router->addRoute(
        		'category',
        		new Zend_Controller_Router_Route_Regex(
        					'([a-z0-9-]*)_c([0-9]*)(_p[0-9]+)?',
        					array(
        						'module' => 'front',
        						'controller' => 'post',
        						'action'	=> 'category',
        						'page' => '1'
        					),
        					array(
        						1 => 'name',
        						2 => 'id',
        						3 => 'page'
        					),
        					'%s_c%s%s'
        			)
        );
        //url ~/canon_p1
        $router->addRoute(
        		'man',
        		new Zend_Controller_Router_Route_Regex(
        					'([a-zA-Z]+)(_p[0-9]+)?',
        					array(
        						'module' => 'front',
        						'controller' => 'pcategory',
        						'action'	=> 'man',
        						'page'		=>"1"
        					),
        					array(
        						1 => 'man_name',
        						2 => 'page'
        					),
        					'%s%s'
        			)
        );
        //url ~/canon/may-in-laser.html
        $router->addRoute(
        		'man_pcategory',
        		new Zend_Controller_Router_Route_Regex(
        					'([a-zA-Z]+)/([a-z0-9-]*)(_p[0-9]+)?',
        					array(
        						'module' => 'front',
        						'controller' => 'pcategory',
        						'action'	=> 'man',
        						'page'		=>"1"
        					),
        					array(
        						1 => 'man_name',
        						2 => 'cat_slug',
        						3 => 'page'
        					),
        					'%s/%s%s'
        			)
        );
        //url ~/gio-hang.html
        $router->addRoute(
        		'cart',
        		new Zend_Controller_Router_Route(
        			'gio-hang.html/:action',
        			array(
        				'module' => 'front',
        				'controller' => 'cart',
        				'action'	=> 'index'
        			)
        		)
        );
        //url ~/gio-hang.html
        $router->addRoute(
        		'print',
        		new Zend_Controller_Router_Route_Static(
        			'in-bao-gia.html',
        			array(
        				'module' => 'front',
        				'controller' => 'cart',
        				'action'	=> 'print'
        			)
        		)
        );
        
        //url ~/gui-don-hang.html
        $router->addRoute(
        		'sendbill',
        		new Zend_Controller_Router_Route_Static(
        		'gui-don-hang.html',
        		array(
        			'module' => 'front',
        			'controller' => 'cart',
        			'action' => 'send'
        		)
        	)
        );
        $router->addRoute(
        		"khuyenmai",
        		new Zend_Controller_Router_Route_Static(
        			'khuyen-mai.html',
        		array(
        				"module" => "front",
        				"controller" => "Promotion",
        				"action" => "index"
        			)
        		)
        );
            	
		//add admin dashboard
		//url = ~/admin
		$router->addRoute(
							'admin_dashboard', 							//route name
							new Zend_Controller_Router_Route_Static(
								'admin',								// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'dashboard',		//controller name
                                    'action' 		=> 'index'			//action name
                                )
                           )

						 );
						 
		//add admin login
		//url = ~/admin/login
		$router->addRoute(
							'admin_login', 								//route name
							new Zend_Controller_Router_Route_Static(
								'admin/login',								// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'login'
                                    
                               	)			//action name
                            )
						 );
		
		//add admin logout
		//url = ~/admin/logout
		$router->addRoute(
							'admin_logout', 							//route name
							new Zend_Controller_Router_Route(
								'admin/logout',							// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'logout')		//action name
                                )

						 );

		//add admin user list
		//url = ~/admin/user/list
		$router->addRoute(
							'admin_user_list', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/list',							// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'list')			//action name
                                )

						 );
						 
		//add admin user create route
		//url = ~/admin/user/create
		$router->addRoute(
							'admin_user_create', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/create',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'create')		//action name
                                )

						 );
		//url = ~/admin/user/edit
		$router->addRoute(
							'admin_user_edit', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/edit/:id',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'edit'
                                )		//action name
                            )

						 );
		//url = ~/admin/user/changepass
		$router->addRoute(
							'admin_user_changepass', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/changepass',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'changePass'
                                )		//action name
                            )

						 );
		//url = ~/admin/user/delete
		$router->addRoute(
							'admin_user_delete', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/delete/:id',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'delete',
                                	'id'			=> ''
                                )		//action name
                            )

						 );
		//url = ~/admin/category/:type/:id
		$router->addRoute(
			'admin_category',
			new Zend_Controller_Router_Route(
				'admin/category/:type/:id/:action',
				array(
					'module'	=> 'admin',
					'controller' => 'category',
					'action' => 'index',
					'type'	=> 'article',
					'id' => ''
				)
			)
		);
		//url = ~/admin/category/search/:type
		$router->addRoute(
			'admin_category_search',
			new Zend_Controller_Router_Route(
				'admin/category/search/:type',
				array(
					'module'	=> 'admin',
					'controller' => 'category',
					'action' => 'search',
					'type'	=> 'article'
				)
			)
		);
		//url = ~/admin/category/delete/:type
		$router->addRoute(
			'admin_category_delete',
			new Zend_Controller_Router_Route(
				'admin/category/delete/:id/:type',
				array(
					'module'	=> 'admin',
					'controller' => 'category',
					'action' => 'delete',
					'type'	=> 'article',
					'id'	=>''
				)
			)
		);
		
		//url = ~/admin/tags/:type/:id
		$router->addRoute(
			'admin_tag',
			new Zend_Controller_Router_Route(
				'admin/tags/:type/:id/:action',
				array(
					'module'	=> 'admin',
					'controller' => 'tag',
					'action' => 'index',
					'type'	=> 'article',
					'id' => ''
				)
			)
		);
		//url = ~/admin/tag/search/:type
		$router->addRoute(
			'admin_tag_search',
			new Zend_Controller_Router_Route(
				'admin/tag/search/:type',
				array(
					'module'	=> 'admin',
					'controller' => 'tag',
					'action' => 'search',
					'type'	=> 'article'
				)
			)
		);
		//url = ~/admin/tag/delete/:type
		$router->addRoute(
			'admin_tag_delete',
			new Zend_Controller_Router_Route(
				'admin/tag/delete/:id/:type',
				array(
					'module'	=> 'admin',
					'controller' => 'tag',
					'action' => 'delete',
					'type'	=> 'article',
					'id'	=>''
				)
			)
		);
		//url = ~/admin/article/create
		$router->addRoute(
			'admin_article_create',
			new Zend_Controller_Router_Route(
				'admin/article/create',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'create'
				)
			)
		);
		//url = ~/admin/article/edit/:id
		$router->addRoute(
			'admin_article_edit',
			new Zend_Controller_Router_Route(
				'admin/article/edit/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'edit',
				)
			)
		);
		//url = ~/admin/article/list
		$router->addRoute(
			'admin_article_list',
			new Zend_Controller_Router_Route(
				'admin/article/list/:page',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'list',
					'page'	=> 1
				)
			)
		);
		//url = ~/admin/article/delete/:id
		$router->addRoute(
			'admin_article_delete',
			new Zend_Controller_Router_Route(
				'admin/article/delete/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'delete',
					'id'	=> ''
				)
			)
		);
		//url = ~/admin/page/create
		$router->addRoute(
			'admin_page_create',
			new Zend_Controller_Router_Route(
				'admin/page/create',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'create'
				)
			)
		);
		//url = ~/admin/page/edit/:id
		$router->addRoute(
			'admin_page_edit',
			new Zend_Controller_Router_Route(
				'admin/page/edit/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'edit',
				)
			)
		);
		//url = ~/admin/page/list
		$router->addRoute(
			'admin_page_list',
			new Zend_Controller_Router_Route(
				'admin/page/list/:page',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'list',
					'page'	=> 1
				)
			)
		);
		//url = ~/admin/page/delete/:id
		$router->addRoute(
			'admin_page_delete',
			new Zend_Controller_Router_Route(
				'admin/page/delete/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'delete',
					'id'	=> ''
				)
			)
		);
		//url = ~/admin/supporter/list
		$router->addRoute(
			'admin_supporter_list',
			new Zend_Controller_Router_Route(
				'admin/supporter/list',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'list'
				)
			)
		);
		//url = ~/admin/supporter/create
		$router->addRoute(
			'admin_supporter_create',
			new Zend_Controller_Router_Route(
				'admin/supporter/create',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'create'
				)
			)
		);
		//url = ~/admin/supporter/edit
		$router->addRoute(
			'admin_supporter_edit',
			new Zend_Controller_Router_Route(
				'admin/supporter/edit/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'edit',
					'id'		 =>''
				)
			)
		);
		//url = ~/admin/supporter/delete
		$router->addRoute(
			'admin_supporter_delete',
			new Zend_Controller_Router_Route(
				'admin/supporter/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'delete',
					'id'		 =>''
				)
			)
		);
		//url = ~/admin/pcategory
		$router->addRoute(
			'admin_pcategory',
			new Zend_Controller_Router_Route(
				'admin/pcategory/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'pcategory',
					'action'	 => 'index',
					'id'		=> ''
				)
			)
		);
		//url = ~/admin/pcategory/delete/id
		$router->addRoute(
			'admin_pcategory_delete',
			new Zend_Controller_Router_Route(
				'admin/pcategory/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'pcategory',
					'action'	 => 'delete',
					'id'		=> ''
				)
			)
		);
		//url = ~/admin/manufacturer
		$router->addRoute(
			'admin_manufacturer',
			new Zend_Controller_Router_Route(
				'admin/manufacturer/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'manufacturer',
					'action'	 => 'index',
					'id'		=> ''
				)
			)
		);
		//url = ~/admin/manufacturer
		$router->addRoute(
			'admin_manufacturer_delete',
			new Zend_Controller_Router_Route(
				'admin/manufacturer/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'manufacturer',
					'action'	 => 'delete',
					'id'		=> ''
				)
			)
		);
		//url = ~/admin/product/list/page
		$router->addRoute(
			'admin_product_list',
			new Zend_Controller_Router_Route(
				'admin/product/list/:page',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'list',
					'page'		 => 1
				)
			)
		);
		//url = ~/admin/product/create
		$router->addRoute(
			'admin_product_create',
			new Zend_Controller_Router_Route(
				'admin/product/create',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'create'
				)
			)
		);
		//url = ~/admin/product/edit/:id
		$router->addRoute(
			'admin_product_edit',
			new Zend_Controller_Router_Route(
				'admin/product/edit/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'edit'
				)
			)
		);
		//url = ~/admin/product/delete/:id
		$router->addRoute(
			'admin_product_delete',
			new Zend_Controller_Router_Route(
				'admin/product/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'delete',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/filter
		$router->addRoute(
			'admin_filter',
			new Zend_Controller_Router_Route(
				'admin/filter/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'filter',
					'action'	 => 'index',
					'id'		 =>	''
				)
			)
		);
		//url = ~/admin/filter/delete/:id
		$router->addRoute(
			'admin_filter_delete',
			new Zend_Controller_Router_Route(
				'admin/filter/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'filter',
					'action'	 => 'delete',
					'id'		 =>	''
				)
			)
		);
		//url = ~/admin/filter/add/value/:id
		$router->addRoute(
			'admin_filter_value',
			new Zend_Controller_Router_Route(
				'admin/filter/value/:filter_id/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'filter',
					'action'	 => 'filtervalue',
					'id'		 =>	''
				)
			)
		);
		//url = ~/admin/filter/edit/value/:id
		$router->addRoute(
			'admin_filter_editvalue',
			new Zend_Controller_Router_Route(
				'admin/filter/edit/value/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'filter',
					'action'	 => 'editValue',
					'id'		 =>	''
				)
			)
		);
		//url = ~/admin/filter/delete/value/:id
		$router->addRoute(
			'admin_filter_deletevalue',
			new Zend_Controller_Router_Route(
				'admin/filter/delete/value/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'filter',
					'action'	 => 'deleteValue'
				)
			)
		);
		//url = ~/admin/bill/list
		$router->addRoute(
			'admin_bill_list',
			new Zend_Controller_Router_Route(
				'admin/bill/list',
				array(
					'module'	 => 'admin',
					'controller' => 'bill',
					'action'	 => 'list'
				)
			)
		);
		//url = ~/admin/bill/view
		$router->addRoute(
			'admin_bill_view',
			new Zend_Controller_Router_Route(
				'admin/bill/view/:id',
				array(
					'module'	 =>'admin',
					'controller' =>'bill',
					'action'	 =>'view',
					'id'  		 =>''
				)
			)
		);
		//url = ~/admin/bill/delete
		$router->addRoute(
			'admin_bill_delete',
			new Zend_Controller_Router_Route(
				'admin/bill/delete/:id',
				array(
					'module'	 =>'admin',
					'controller' =>'bill',
					'action'	 =>'delete',
					'id'  		 =>''
				)
			)
		);
		
		//url = ~/admin/banner
		$router->addRoute(
			'admin_banner',
			new Zend_Controller_Router_Route(
				'admin/banner/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'banner',
					'action'	 => 'index',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/menu
		$router->addRoute(
			'admin_menu',
			new Zend_Controller_Router_Route(
				'admin/menu/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'menu',
					'action'	 => 'index',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/menu/delete
		$router->addRoute(
			'admin_menu_delete',
			new Zend_Controller_Router_Route(
				'admin/menu/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'menu',
					'action'	 => 'delete',
					'id'		 => ''
				)
			)
		);
		$router->addRoute(
			'admin_ajax_filters',
			new Zend_Controller_Router_Route(
				'admin/ajax/getfilters',
				array(
					'module'	 => 'admin',
					'controller' => 'ajax',
					'action'	 => 'getfilters'
				)
			)
		);
		$router->addRoute(
			'admin_ajax_pageslug',
			new Zend_Controller_Router_Route(
				'admin/ajax/pageslug',
				array(
					'module'	 => 'admin',
					'controller' => 'ajax',
					'action'	 => 'pageslug'
				)
			)
		);
		//route cho khuyen mai
		$router->addRoute(
			'admin_promotion',
			new Zend_Controller_Router_Route(
				'admin/promotion',
				array(
					'module'	=> 'admin',
					'controller'=> 'promotion',
					'action'	=> 'index'
				)
			)
		);

		$router->addRoute(
			'admin_tag',
			new Zend_Controller_Router_Route(
				'admin/tag/:id',
				array(
					'module'	=> 'admin',
					'controller'=> 'tag',
					'action'	=> 'index',
                              'id'        => ''
				)
			)
		);
            $router->addRoute(
			'admin_tag_delete',
			new Zend_Controller_Router_Route(
				'admin/tag/delete/:id',
				array(
					'module'	=> 'admin',
					'controller'=> 'tag',
					'action'	=> 'delete',
                              'id'        => ''
				)
			)
		);
	}
	
}